/**
 * Created by 078826 on 2017/7/24.
 */
/*系统设置隐藏*/
function hideSysSet(){
    $('.sysSet-guide').hide();
}

function goToSet(){
    hideSysSet();
    checkedTab(2);
}


/*超过10天隐藏提示*/
function hoverHide(){
    var startDate = new Date(Date.UTC(2017,8,19,0,0,0));//初始化为19号版本上线时间
    var s = startDate.getTime();
    var mydate = new Date();
    var t=mydate.getTime();
    var result = parseInt(Math.abs(t - s) / 1000 / 60 / 60 / 24);
    if(result > 2){
        $('.fixed-btn-box .tip').hide();
    }
}

/*意见反馈显示*/
function showFeedTip(){
    hoverHide();
    $('.fixed-btn-box .tip').css({
        'height': '244px'
    });
}

/*隐藏提示语*/
function hideTip(){
    $('.fixed-btn-box .tip').css({
        'height':'0px'
    });
}

/**
 * 获取当前用户已处理反馈意见数
 **/
function findProcessedNumber(){
    $.get(LOGSTATISTICS_SERVICE_URL + "menuFeedback/findProcessedNumber",function(data){
        if(data.status == "SUCCESS" && data.body > 0){
            $(".feed-back .data_num mark").html(data.body);
            $(".feed-back .data_num").show();
        }else{
            $(".feed-back .data_num").hide();
        }
    });
}

$(function(){
    hoverHide();//加载时判断时间是否超时
    /*常用菜单设置提示*/
    /*$.get(CUSTOM_SERVICE_URL + 'customMenuInit/isInitUser', function(data){
        if (data.status == 'SUCCESS') {
            if (data.body) {
                // 需要操作指引
                $('.sysSet-guide').show();
            } else {
                // 不需要操作指引
                $('.sysSet-guide').hide();
            }
        } else if (data.status == 'FAILURE') {
            // 失败   失败信息data.body
            console.warn(data.body);
        } else if (data.status == 'ERROR') {
            // 异常
            console.error(data.body);
        }
    });*/

    $('.fixed-btn-box .feed-back').hover(function(){
        showFeedTip();
    },function(){
        hideTip();
    });

    /*点击别处隐藏拖动提示*/
    $(document).on("click", function () {
        hideTip();
    });
    $('.fixed-btn-box .tip p').on("click", function () {
        hideTip();
    });
    // 阻止冒泡
    $('.fixed-btn-box .tip').on("click", function () {
        stopEvent();
    });
    $('.fixed-btn-box .tip').hover(function () {
        stopEvent();
    });
    /*弹窗拖动*/
    $('.modal-dialog').draggable({
        handle: ".modal-header"   // 只能点击头部拖动
    });

    /*固定按钮拖动*/
    $('.fixed-btn-box').draggable();
    $(document).on('mousemove','.fixed-btn-box',function(){
        $('.fixed-btn-box').draggable({
            axis: 'y',
            scroll: true,
            containment: '#mainAreaPanel-body'
        });
    });
    $(document).on('click', '.fixed-btn-box .feed-back', function () {
        popFeedBack();
        stopEvent();
    });
    $(document).on('click', '.fixed-btn-box .knowledge-base', function () {
        toKnowledge();
        stopEvent();
    });
    $(document).on('click', '.fixed-btn-box .go-top', function () {
        $('body,html').animate({ scrollTop: 0 }, 250);
        stopEvent();
    });

    //定时更新已处理反馈意见数
    window.setInterval(findProcessedNumber,1000 * 60 * 30);
    findProcessedNumber();
});

window.onload = function() {
    var url =  $('.fixed-btn-box .tip img').attr("src");
    $('.fixed-btn-box .tip img').attr('src',url);
};
